﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EulerNo2
{
    class Program
    {
        static void Main(string[] args)
        {
            //euler problem 2
            //By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

            //start old value at 1 since the 2nd number is two
            int oldValue = 0;
            int value = 1;
            int nextvalue = 0;
            int sum = 0;

            while (true)
            {
                //check if bust
                if (nextvalue >= 4000000)
                    break;

                //add value
                nextvalue = oldValue + value;
                
                //check if even term
                int valint = nextvalue / 2;
                double valdouble = Convert.ToDouble(nextvalue) / 2;

                if (valdouble == valint)
                {
                    sum += nextvalue;
                }

                //next number in the serie
                oldValue = value;
                value = nextvalue;
            }

            Console.WriteLine("value: " +nextvalue.ToString() + "\nsum: " + sum.ToString());
            Console.Read();
        }
    }
}
